package testing;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import cash_access.Account;
import cash_access.Account_Stub;
import cash_access.OverdraftException;

import branch_access.Manager;

import application.bank.Account_Impl;
import application.bank.Manager_Impl;


import mware_lib.NameService;
import mware_lib.ObjectBroker;
import mware_lib.StubSkeletonCom;


public class TestFrame {
	static int port = 44444;

	public static void main(String[] args) {
		ObjectBroker objbrk_remote = ObjectBroker.getBroker("localhost", port);
		NameService ns_remote = objbrk_remote.getNameService();

		ObjectBroker objbrk_locale = ObjectBroker.getBroker("localhost", port);
		NameService ns_locale = objbrk_locale.getNameService();
		
//		Account_Impl aImpl = new Account_Impl("Egon");
//		ns_remote.rebind(aImpl, aImpl.accountID);
//		
//		Account aLoc = (Account)ns_locale.resolve(aImpl.accountID);
//		System.out.println("vorher: "+ aLoc.getBalance() + "�");
//		aLoc.deposit(100.0);
//		
//		try {
//			aLoc.withdraw(50);
//		} catch (OverdraftException e) {
//			System.out.println("da wollte jemand mehr abheben, als er hat!!");
//		}
//		
//		System.out.println("nachher: "+ aLoc.getBalance() + "�");
		
		Manager mRem = new Manager_Impl(ns_remote);
		ns_remote.rebind(mRem, "Boss");
		
		Manager mLoc = (Manager) ns_locale.resolve("Boss");
		String hugo_acc = mLoc.createAccount("Hugo");
		System.out.println("Hugos kontonummer: "+hugo_acc);
//		mLoc.removeAccount(hugo_acc);

		Account aLoc = (Account)ns_locale.resolve(hugo_acc);
		System.out.println("vorher: "+ aLoc.getBalance() + "�");
		aLoc.deposit(100.0);
		
		try {
			aLoc.withdraw(50);
		} catch (OverdraftException e) {
			System.out.println("da wollte jemand mehr abheben, als er hat!!");
		}
		
//		for (int i = 0; i < 100; i++) {
//			aLoc.deposit(100.0);
//			System.out.println("nachher: "+ aLoc.getBalance() + "�");
//		}
		
		
		
	}

	
}